<?php
namespace App\Domain\Appfc114;

use App\Model\Appfc114\News as ModelNews;

class News  {

    protected $query;

    function __construct() {
        $this->query = new QueryCommon();
    }

    public function getlist(){
        $param = \PhalApi\DI()->request->getAll();
        $model = new ModelNews();

        $where = [];
        $whereRaw = " web_contentindex.flag = 1 ";
        $order = isset($param['order'])?$param['order']." desc ":" web_contentindex.postdate desc ";

        if(isset($param['keyword']) && !empty($param['keyword']))//关键字查询
            $whereRaw.= " and (web_contentindex.title like '%{$param['keyword']}%')";

        if(isset($param['cid']) && $param['cid']!='')
            $where["cid"]=$param['cid'];

        $page = isset($param["page"])?$param["page"]:1;
        $limit = isset($param["pageSize"])?$param["pageSize"]:30;
        $limitdata = $this->query->getPaginationDC($page,$limit);
        $items = $model->getListItems($where,$whereRaw, 1,$limitdata, $order);

        foreach ($items as $key => $value) {
            $items[$key]["create_date_val"] = date("Y-m-d",$value["write_date"]);
        }

        return $items;
    }

    public function Detail($news_id){
        $model = new ModelNews();
        $info = $model->getDetail($news_id,1);
        $info["create_date_val"] = date("Y-m-d",$info["create_date"]);
        return $info;
    }

}
